/**
 * @(#)LoggerFactory.java Mar 6, 2007
 *
 * Copyright (c) 2005-2010 Psiqueware S.A. de C.V. All Rights Reserved.
 * This software is the proprietary information Psiqueware S.A. de C.V.
 * Use is subject to license terms.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 *
 * <br/>Usuario : AngelElectrico
 * <br/>Creaci&oacute;n: Mar 6, 2007 - 1:40:11 PM
 * <br/>
 * <br/>
 * <br/><t5>Cambios :</t5>
 * <br/><b>Fecha | Autor  |  Cambios</b>
 * <ul>
 * <li>Mar 6, 2007 | <a href = "mailto:AngelElectrico@PsiqueWare.com">Angel El&eacute;ctrico</a> | Creaci&oacute;n del Objeto.</li>
 * <li>Nov 3, 2008 | <a href = "mailto:AngelElectrico@PsiqueWare.com">Angel El&eacute;ctrico</a> | Se actualiza la f&aacute;brica para incluir al logger via standard out.</li>
 * </ul>
 */

package com.psiqueware.alheli.logging;

import com.psiqueware.alheli.logging.commons.LoggerApacheCommons;
import com.psiqueware.alheli.logging.log4j.Logger4j;
import com.psiqueware.alheli.logging.logback.LoggerBack;
import com.psiqueware.alheli.logging.standardOut.LoggerStandardOut;
import org.apache.log4j.Level;

/**
 * F&aacute;brica de Loggers.
 * <br/>Paquete Original: com.psiqueware.basico.logging
 * <br/>Nombre  Original: LoggerFactory
 * <br/>Oprima para ver : <a href="LoggerFactory.java.html"><i>C&oacute;digo Fuente</i> </a>
 *
 * @author <a href="mailto:AngelElectrico@PsiqueWare.com">Angel El&eacute;ctrico</a>
 * @version Revision: 1.1 Mar 6, 2007 1:40:11 PM
 * @noinspection ClassWithoutLogger
 */
public final class LoggerFactory
{

    /**
     * {@link TipoLogger} sobre el que se producir&aacute;n {@link Logger}s.
     */
    private static TipoLogger s_tipo = TipoLogger.STANDARD_OUT;

    /**
     * Constructor de LoggerFactory.
     */
    public LoggerFactory()
    {
    }

    /**
     * Obtenemos un nuevo {@link Logger}.
     *
     * @param clazz que se esta Loggeando.
     *
     * @return nuevo Logger para la clase.
     */
    public static Logger getLogger(Class clazz)
    {
        Logger logger = null;
        switch (s_tipo)
        {
            case STANDARD_OUT:
                logger = new LoggerStandardOut();
                break;
            case LOG_4J:
                logger = new Logger4j(clazz);
                break;
            case COMMONS:
                logger = new LoggerApacheCommons(clazz);
                break;
            case LOGBACK:
                logger = new LoggerBack(clazz);
                break;
        }
        return logger;
    }


    /**
     * Obtenemos un nuevo {@link Logger}.
     *
     * @param loggerStr cadena para identificarlo.
     *
     * @return nuevo Logger para la clase.
     */
    public static Logger getLogger(String loggerStr)
    {
        Logger logger = null;
        switch (s_tipo)
        {
            case STANDARD_OUT:
                logger = new LoggerStandardOut();
                break;
            case LOG_4J:
                logger = new Logger4j(loggerStr);
                break;
            case COMMONS:
                logger = new LoggerApacheCommons(loggerStr);
                break;
            case LOGBACK:
                logger = new LoggerBack(loggerStr);
                break;
        }
        return logger;
    }


    /**
     * Returns the {@link TipoLogger} sobre el que se producir&aacute;n {@link Logger}s.
     *
     * @return value from 's_tipo'.
     *
     * @see TipoLogger
     */
    public static TipoLogger getTipo()
    {
        return s_tipo;
    }

    /**
     * Establece el {@link TipoLogger} sobre el que se producir&aacute;n {@link Logger}s.
     *
     * @param tipo nuevo valor para 's_tipo'.
     *
     * @see TipoLogger
     */
    public static void setTipo(final TipoLogger tipo)
    {
        LoggerFactory.s_tipo = tipo;
    }

    /**
     * Establece el nivel de loggeo como DEBUG.
     */
    public static void setNivelDebug()
    {
        switch (s_tipo)
        {
            case STANDARD_OUT:
                LoggerStandardOut.NIVEL = 0;
                break;
            case LOG_4J:
                Logger4j.Util.cambiarNivelLogging(Level.DEBUG);
                break;
            case COMMONS:
                //No aplica, configurar nivel inferior
                break;
            case LOGBACK:
                LoggerBack.Util.cambiarNivelLogging(ch.qos.logback.classic.Level.DEBUG);
                break;
        }
    }

    /**
     * Establece el nivel de loggeo como INFO.
     */
    public static void setNivelInfo()
    {
        switch (s_tipo)
        {
            case STANDARD_OUT:
                LoggerStandardOut.NIVEL = 1;
                break;
            case LOG_4J:
                Logger4j.Util.cambiarNivelLogging(Level.INFO);
                break;
            case COMMONS:
                //No aplica, configurar nivel inferior
                break;
            case LOGBACK:
                LoggerBack.Util.cambiarNivelLogging(ch.qos.logback.classic.Level.INFO);
                break;
        }
    }

    /**
     * Establece el nivel de loggeo como Warning.
     */
    public static void setNivelAlerta()
    {
        switch (s_tipo)
        {
            case STANDARD_OUT:
                LoggerStandardOut.NIVEL = 3;
                break;
            case LOG_4J:
                Logger4j.Util.cambiarNivelLogging(Level.WARN);
                break;
            case COMMONS:
                //No aplica, configurar nivel inferior
                break;
            case LOGBACK:
                LoggerBack.Util.cambiarNivelLogging(ch.qos.logback.classic.Level.WARN);
                break;
        }
    }


}

